/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var VNize = function(str) {

    var vnkey = {
        'a': '[aáàảãạâấầẩẫậăắằẳẵặ]',
        'e': '[eéèẻẽẹêếềểễệ]',
        'd': '[dđ]',
        'i': '[iíìỉĩị]',
        'o': '[oóòỏõọôốồổỗộơớờởỡợ]',
        'u': '[uúùủũụưứừửữự]',
        'y': '[yýỳỷỹỵ]'
    };

    var regx = function(query) {

        pattern = '';

        for (j = 0; j < query.length; ++j) {
            ch = query[j];

            if (vnkey.hasOwnProperty(ch)) {
                pattern += vnkey[ch];
            } else {
                pattern += ch;
            }
        }
        return new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + pattern + ")(?![^<>]*>)(?![^&;]+;)", "gi");
    }



    var VietnameseString = function() {

        this.match = function(s1) {
            return str.match(regx(s1))
        };

        this.test = function(s1) {
            return str.test(regx(s1))
        };

        this.replace = function(s1, s2) {
            return str.replace(regx(s1), s2)
        };

        this.removeAccent = function(){
            str = str.replace(regx("a"),"a");
            str = str.replace(regx("e"),"e");
            str = str.replace(regx("d"),"d");
            str = str.replace(regx("i"),"i");
            str = str.replace(regx("o"),"o");
            str = str.replace(regx("u"),"u");
            str = str.replace(regx("y"),"y");

            return str;
        }
    };
    return new VietnameseString();

}



String.prototype.VNize = function() {
    return VNize(this)
}

